package oauth

import (
	"context"
	"micro-oauth/datamodels/autherror"
	"micro-oauth/datamodels"
	"micro-oauth/datamodels/params"
)

// OauthService提供 各个partner管理他们自己数据 的功能, OauthService都只能抛出hexError
type OauthServiceInterface interface {
	GetUserById(ctx context.Context, userId uint64) (*datamodels.User, autherror.HexError)

	GetUserDetailData(ctx context.Context, userId uint64) (*datamodels.UserDetailData, autherror.HexError)
	GetUserWithPreload(ctx context.Context, userId uint64) (*datamodels.User, autherror.HexError)
	GetClientById(clientId string) (*datamodels.Client, autherror.HexError)
	ListUser(ctx context.Context, req *params.UserListRequest) (users []*datamodels.User, total uint64, hexerr autherror.HexError)
	UserLogin(clientId, username, pwd, state, scope, redirectURI string, deviceUUID string) (
		*datamodels.Client, *datamodels.User, *datamodels.Token, autherror.HexError,
	)

	DisableUser(ctx context.Context, req *params.UserDisableRequest) (bool, autherror.HexError)
	UpdateUser(ctx context.Context, req *params.UserUpdateRequest) (*datamodels.User, autherror.HexError)
	Authenticate(ctx context.Context, req *params.AuthenticateRequest) (*params.AuthenticateResponse, autherror.HexError)
	DeleteUser(ctx context.Context, userId uint64) autherror.HexError
	AddUser(ctx context.Context, req *params.UserCreateRequest) (*datamodels.User, autherror.HexError)
	AddUserRole(ctx context.Context, req *params.UserAddRoleRequest) autherror.HexError
	CheckMail (ctx context.Context,req *params.UserPassWdMailReq)  (*datamodels.User, autherror.HexError)
	ResetUserPassWdPre(ctx context.Context,req *params.UserPassWdMailReq) autherror.HexError
	ResetPassWdByNew(ctx context.Context,req *params.UserNewPassWdResetReq) autherror.HexError

	// role updated
	ListRoles(ctx context.Context, req *params.RoleListRequest) (roles []*datamodels.Role, total uint64, hexerr autherror.HexError)
	GetRoleDetail(ctx context.Context, roleId uint64) (*datamodels.Role, autherror.HexError)
	AddRole(ctx context.Context, req *params.RoleCreateRequest) (*datamodels.Role, autherror.HexError)
	UpdateRole(ctx context.Context, req *params.RoleUpdateRequest) (*datamodels.Role, autherror.HexError)
	DeleteRole(ctx context.Context, roleId uint64) autherror.HexError
	AddRolePermissionInfos(ctx context.Context, roleId uint64, req *params.RoleAddPermissionInfosRequest) autherror.HexError

	// permission related
	AddPermission(ctx context.Context, req *params.PermissionCreateRequest) (*datamodels.Permission, autherror.HexError)
	GetPermissionDetail(ctx context.Context, permissionId uint64) (*datamodels.Permission, autherror.HexError)
	ListPermission(ctx context.Context, req *params.PermissionListRequest) (permis []*datamodels.Permission, total uint64, hexerr autherror.HexError)
	UpdatePermission(ctx context.Context, req *params.PermissionUpdateRequest) (*datamodels.Permission, autherror.HexError)
	AddPermissionAPIs(ctx context.Context, req *params.PermissionAddAPIsRequest) autherror.HexError
	DeletePermission(ctx context.Context, permissionId uint64) autherror.HexError
	BatchReplacePermissionMethod(context.Context,params.PermissionMethodRequest)autherror.HexError

	// client related
	ListClient(ctx context.Context, req *params.ClientListRequest) (clients []*datamodels.Client, total uint64, hexerr autherror.HexError)
	IssuePosToken(ctx context.Context, clientId, clientSecret string) (*datamodels.Token, autherror.HexError)
	CreateOrGetPosClient(ctx context.Context, req *datamodels.CreatePosClientRequest) (*datamodels.Client, autherror.HexError)
	ListHomePageScope(ctx context.Context, partnerId uint64) ([]*HomePageScopeResponse, autherror.HexError)

	// device related
	DeviceExist(ctx context.Context, uuid string) (bool, autherror.HexError)
	AddDevice(ctx context.Context, req *params.DeviceCreateRequest) (*datamodels.Device, autherror.HexError)
	DeleteDevice(ctx context.Context, deviceId uint64) autherror.HexError
	UpdateDevice(ctx context.Context, deviceId uint64, req *params.DeviceUpdateRequest) (*datamodels.Device, autherror.HexError)
	ListDevice(ctx context.Context, req *params.DeviceListRequest) ([]*datamodels.Device, uint64, autherror.HexError)
	GetDeviceById(ctx context.Context, deviceId uint64) (*datamodels.Device, autherror.HexError)
	CheckDeviceExist(ctx context.Context, uuid string) (*datamodels.Device, autherror.HexError)

	// token
	RefreshToken(ctx context.Context, accessToken, refreshToken string) (*datamodels.Token,autherror.HexError)

	Close()

	//mail rule config
	AddUserMailRule(ctx context.Context,req *params.UserPassWdRuleReq) (bool,autherror.HexError)
	GetUserMailRule(ctx context.Context,userId uint64) (*datamodels.PassWordRule,autherror.HexError)
	UpdateUserMailRule(ctx context.Context,req *params.UserPassWdRuleReq)(bool,autherror.HexError)
	GetCommonRule(ctx context.Context) (*datamodels.PassWordRule,autherror.HexError)

	// force update user rule
	ForceUpdatePassWord(ctx context.Context,req *params.ResetPassWordReq)(string,autherror.HexError)
}
